<template>
	<view>
		<cu-custom bgColor="bg-gradual-red" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">分类</block>
		</cu-custom>
		<view class="VerticalBox">
			<scroll-view class="VerticalNav nav" scroll-y scroll-with-animation :scroll-top="verticalNavTop" style="height:calc(100vh - 150upx)">
				<view class="cu-item" :class="index==tabCur?'text-green cur':''" v-for="(item,index) in categories" :key="index" @tap="TabSelect"
				 :data-id="index">
					<text class="text-cut">
							{{item.name}}
					</text>
					
					
				</view>
			</scroll-view>
			<scroll-view class="VerticalMain" scroll-y scroll-with-animation style="height:calc(100vh - 150upx)"
			 :scroll-into-view="'main-'+mainCur" >
				<view class="padding-lr-xs" v-for="(item,index) in categories" :key="index" :id="'main-'+index">
					<view class="cu-bar solid-bottom bg-white">
						<view class="action">
							<text class="cuIcon-title text-green"></text> {{item.name}}
						</view>
					</view>
					
					<!-- 二级分类循环 但是不显示名称 （因为版面太窄） -->
					<view v-for="(item2,index2) in item.children" :key="index2">
							<!--肯定放一些小类  第三层循环  -->
							<view class="cu-list grid col-3" >
										<view class="cu-item" v-for="(item3,index3) in item2.children" :key="index3" >
											<navigator  open-type="navigate" :url=" '../product/product?id='+item3.id ">
												<view class="cuIcon-emoji text-red"></view>
											</navigator>	
											<text>{{item3.name}}</text>
										</view>
							</view>
						
						
					</view>
					
				
					
				</view>
			</scroll-view> 		
	
			
		</view>	



		
		
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tabCur: 0,
				mainCur: 0,
				verticalNavTop: 0,
				categories:[]
			
			}
		},
		onLoad() {
			this.init()
		},
		methods: {
			TabSelect(e){
				this.tabCur = e.currentTarget.dataset.id;
				this.verticalNavTop = (e.currentTarget.dataset.id - 1) * 50;
				this.mainCur = e.currentTarget.dataset.id  ; //id=index
				
			},
			init:function(){
				this.$api.__api__categories().then((res)=>{
					this.categories = res.data;
					console.log(res.data)
				});
			}
			
		}
	}
</script>

<style>
	.VerticalNav.nav {
		width: 200upx;
		white-space: initial;
	}
	
	.VerticalNav.nav .cu-item {
		width: 100%;
		text-align: center;
		background-color: #fff;
		margin: 0;
		border: none;
		height: 50px;
		position: relative;
	}
	
	.VerticalNav.nav .cu-item.cur {
		background-color: #f1f1f1;
	}
	
	.VerticalNav.nav .cu-item.cur::after {
		content: "";
		width: 8upx;
		height: 30upx;
		border-radius: 10upx 0 0 10upx;
		position: absolute;
		background-color: currentColor;
		top: 0;
		right: 0upx;
		bottom: 0;
		margin: auto;
	}
	
	.VerticalBox {
		display: flex;
	}
	
	.VerticalMain {
		background-color: #f1f1f1;
		flex: 1;
	}
</style>
